%% Comparative Statics Analysis
% Code performs the comparative statics analysis and saves the results

%% Initial values
f=0;
f_entrant=0;
f_incumbent=0;
mean_leverage=0;
var_leverage=0;
mean_incidence=0;
exit_rate=0;
m_entrant=0;
m_incumbent=0;
flow_new_entrants=0;
Mom = table(f, f_entrant, f_incumbent, mean_leverage, var_leverage, mean_incidence, exit_rate, m_entrant, m_incumbent, flow_new_entrants);
names = {'f','f_e','f_i','Mean: Leverage','Var: Leverage','Mean: Incidence','Exit Rate', 'Mass entrants', 'Mass incumbents', 'Flow new entrants'};

%% gamma
gamma_vec = (1.9048:(2.1053-1.9048)/12:2.1053)';
Mom_gamma = repmat(Mom,length(gamma_vec),1);
parfor i=1:length(gamma_vec)
	[Mom_gamma(i,:), dataSimg] = csMoments(bParams,oParams,setts,gamma_vec(i),'gamma');
end
Mom_gamma = [table(gamma_vec),Mom_gamma]; 
% Save results
writetable(Mom_gamma,strcat(path_tab,'Gamma','.txt'),'Delimiter',' ');

%% beta
beta_vec = (4.066*0.8:(4.066*1.2-4.066*0.8)/12:4.066*1.2)';
Mom_beta = repmat(Mom,length(beta_vec),1);
parfor i=1:length(beta_vec)
	Mom_beta(i,:) = csMoments(bParams,oParams,setts,beta_vec(i),'beta');
end
Mom_beta = [table(beta_vec),Mom_beta];
% Save results
writetable(Mom_beta,strcat(path_tab,'Beta','.txt'),'Delimiter',' ');

%% H
H_vec = (3.35/(1-oParams.pi)*0.95:(3.35/(1-oParams.pi)*1.05-3.35/(1-oParams.pi)*0.95)/12:3.35/(1-oParams.pi)*1.05)';
Mom_H = repmat(Mom,length(H_vec),1);
parfor i=1:length(H_vec)
	Mom_H(i,:) = csMoments(bParams,oParams,setts,H_vec(i),'H')
end
Mom_H = [table(H_vec),Mom_H];
% Save results
writetable(Mom_H,strcat(path_tab,'H','.txt'),'Delimiter',' ');

%% H_elasticity
H_vec_ext = (bParams.H*1.025:(bParams.H*1.10-bParams.H*1.025)/24:bParams.H*1.10)';
Mom_H_ext = repmat(Mom,length(H_vec_ext),1);
parfor i=1:length(H_vec_ext)
	Mom_H_ext(i,:) = csMoments(bParams,oParams,setts,H_vec_ext(i),'H');
end
Mom_H_ext = [table(H_vec_ext),Mom_H_ext];
% Save results
writetable(Mom_H_ext,strcat(path_tab,'H_ext','.txt'),'Delimiter',' ');

%% pi
pi_vec = (0.10:(0.20-0.10)/12:0.20)';
Mom_pi= repmat(Mom,length(pi_vec),1);
parfor i=1:length(pi_vec)
	Mom_pi(i,:) = csMoments(bParams,oParams,setts,pi_vec(i),'pi');
end
Mom_pi = [table(pi_vec),Mom_pi];
% Save results
writetable(Mom_pi,strcat(path_tab,'pi','.txt'),'Delimiter',' ');
